package com.broad.commerce.code.services.jdbc;

import com.broad.commerce.code.base.AbstractJavaService;
import com.broad.commerce.code.modules.BaseModule;
import com.broad.commerce.code.modules.jdbc.MybatisModule;
import com.broad.commerce.code.services.base.BaseInterfaceService;
import com.broad.commerce.web.exception.ServiceException;
import org.springframework.stereotype.Service;

/**
 * @author stephen
 * @version V1.0
 * @date 2022-02-07 16:06
 * @description: MapperModuleService
 **/
@SuppressWarnings("DuplicatedCode")
@Service
public class MybatisModuleService extends AbstractJavaService {
	/**
	 * package com.broad.commerce.jdbc.repository.system.mybatis;
	 * <br/>
	 * import com.broad.commerce.jdbc.entity.system.SystemPermission;
	 * import org.apache.ibatis.annotations.Mapper;
	 * import org.springframework.stereotype.Repository;
	 * import java.util.List;
	 * <br/>
	 * **
	 * * @author stephen
	 * * @version V1.0
	 * * @date 2020-08-28 10:01
	 * * @description: SystemPermissionMapper
	 * **
	 * @Repository
	 * @Mapper <br/>
	 * public interface SystemPermissionMapper {
	 * List<SystemPermission> selectListByUser(Long sysUserId);
	 * List<SystemPermission> selectListByUserName(String userName);
	 * List<SystemPermission> selectListByPath(String path);
	 * List<String> selectListByRoleCode(String roleCode);
	 * List<String> selectAllPermissionCodes();
	 * }
	 **/
	@Override
	public String createClassCode(BaseModule baseModule) {
		if (!(baseModule instanceof MybatisModule)) {
			throw new ServiceException("传入参数类型错误！应为 MybatisModule");
		}
		return super.createClassCode(baseModule);
	}

	/***
	 * Create import code.
	 * @param sb the sb
	 * @param baseModule the base module
	 **/
	@Override
	protected void createImportCode(StringBuilder sb, BaseModule baseModule) {
		MybatisModule mybatisModule = (MybatisModule) baseModule;
		//@off
		sb.append("import ").append(mybatisModule.getEntityFullClassName()).append(";\n")
		  .append("import org.apache.ibatis.annotations.Mapper;").append("\n")
		  .append("import org.springframework.stereotype.Repository;").append("\n")
		  .append("\n")
		  .append("import java.util.List;").append("\n")
		  .append("\n");//@on
	}

	/**
	 * Create annotation code.
	 * @param sb the sb
	 * @param baseModule the base module
	 */
	@Override
	protected void createAnnotationCode(StringBuilder sb, BaseModule baseModule) {
		//@off
		sb.append("@Repository").append("\n")
		  .append("@Mapper").append("\n");//@on
	}

	/**
	 * Create class start tag.
	 * @param sb the sb
	 * @param baseModule the base module
	 */
	@Override
	protected void createClassStartTag(StringBuilder sb, BaseModule baseModule) {
		MybatisModule mybatisModule = (MybatisModule) baseModule;
		BaseInterfaceService.createClassStartTag(sb, mybatisModule);
	}

	/**
	 * Create class content.
	 * @param sb the sb
	 * @param baseModule the base module
	 */
	@Override
	protected void createClassContent(StringBuilder sb, BaseModule baseModule) {
		MybatisModule mybatisModule = (MybatisModule) baseModule;
		BaseInterfaceService.createClassContent(sb, mybatisModule);
	}
}
